<template>
  <div id="mobile-navbar-page" class="mobile-navbar-box" :class="[showBottomBorder&&'border']">
    <div class="content">
      <span>{{name}}</span>
    </div>
    <div class="actions-box">
      <div class="left" @click="back" style="display:flex;align-items:center;">
        <svg v-if="buttonType=='icon'" class="back-svg-icon" aria-hidden="true">
          <use xlink:href="#keowledge-mobile-fanhui"></use>
        </svg>
        <div v-else class="cancle-button">{{$t('message.buttons.cancal')}}</div>
      </div>
      <div style="display:flex;align-items:center;">
        <slot name="right"></slot>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import {
  ref,
  reactive,
  toRefs,
  watch ,
  onMounted,
  getCurrentInstance
} from 'vue' 
import type {ComponentInternalInstance} from 'vue'
const instance: any = getCurrentInstance() as ComponentInternalInstance;
const proxy: any = instance.proxy as any; // 访问 proxy 属性
import { useHookI18n } from '@/hooks/i18n'
const { locale,$t } = useHookI18n()
import { setSessionStore, getSessionStore} from '@/utils/store.js'
import useUserInfoStore from '@/store/userInfo';
const userStore = useUserInfoStore()
import { useRouter } from "vue-router"
const router = useRouter();

const emit = defineEmits(["back"])
const props = defineProps({
  name:{
      type:String,
      default:''
    },
    showBottomBorder:{
      type:Boolean,
      default:false
    },
    buttonType:{
      type:String,
      default:'icon'
    },
    isBackPath:{
      type:Boolean,
      default:true
    },
    isDir:{
      type:Boolean,
      default:false
    }
})
const  routerList = ref([])
onMounted(()=>{
  routerList.value = getSessionStore({name:'mobileRouterList'}) || []
})
function back(){
  let path  = ''
  if(!userStore.access_token){
    path="/mobile/login"
  }else{
    if(props.isBackPath){
      path ='/mobile/index'
      if(routerList.value.length!=0){
        path = routerList.value.pop()
        setSessionStore({name:'mobileRouterList',content:routerList.value})
      }
    }
  }
  emit('back',path)
}
</script>
<style lang="scss" scoped>
.mobile-navbar-box{
  height: 3.125rem;
  padding: 0px 1.125rem 0px 1.25rem;
  position: relative;
  display: flex;
  justify-content: center;
  z-index: 99;
  .content{
    z-index: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 3.125rem;
    color: #363B4C;
    font-size: 1rem;
    text-align: center;
    @include SourceHanSansCN-Bold;
    span{
      width: calc(100vw - 7.5rem);
      text-overflow: ellipsis;
      white-space: nowrap;
      overflow: hidden;
    }
  }
  .actions-box{
    position: absolute;
    top: 0px;
    z-index: 1;
    width: calc(100% - 2.6875rem);
    display: flex;
    align-items: center;
    height: 3.125rem;
    justify-content: space-between;
    .left{
      .cancle-button{
        width: 1.75rem;
        color: #363B4C;
        @include SourceHanSansCN-Regular;
        font-size: .875rem;
      }
      .back-svg-icon{
        width: 1rem;
        height: 1rem;
      }
    }
  }
}
.border{
  border-bottom: 1px solid #EEEFF0;
}
</style>